<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>管理员列表-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/lib/jquery-2.1.3.min.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="weadmin-body">
    <div class="weadmin-block">
        <button class="layui-btn" onclick="showADD()"><i class="layui-icon"></i>添加</button>
    </div>
    <table class="layui-table">
        <colgroup>
            <col width="60">
            <col width="250">
            <col width="250">
        </colgroup>
        <thead>
        <tr>
            <th>ID</th>
            <th>卡号</th>
            <th>操作</th>
        </thead>
        <tbody>
        <tr th:each="rfid : ${rfids}">
            <td th:id="'rfid_id'+${rfid.id}" th:text="${rfid.id}">1</td>
            <td th:id="'rfid_number'+${rfid.id}" th:text="${rfid.carNumber}">1111111</td>
            <td class="td-manage">
                <a th:id="'del'+${rfid.id}" title="删除" onclick="del(this.id)" href="javascript:;">
                    <i class="layui-icon">&#xe640;</i>
                </a>
                <a th:id="'edit'+${rfid.id}" title="编辑" onclick="showEDIT(this.id)" href="javascript:;">
                    <i class="layui-icon">&#xe642;</i>
                </a>
            </td>
        </tr>
        </tbody>
    </table>
</div>
<div style="margin: 10px;display: none" id="showAddRFID">
    <p>卡号</p>
    <input id="rfid" name="rfid"  type="text" lay-verify="required" class="layui-input" >
    <hr class="hr15">
    <input id="addworker" onclick="add()" value="添加" lay-submit lay-filter="login" style="width:100%;" type="submit">
    <hr class="hr15">
    <input id="back" onclick="back()" value="取消" lay-submit lay-filter="login" style="width:100%;" type="submit">
    <hr class="hr15">
</div>
<div style="margin: 10px;display: none" id="showEditRFID">
    <p>卡号</p>
    <input id="rfid_edit" name="rfid"  type="text" lay-verify="required" class="layui-input" >
    <hr class="hr15">
    <input id="edit" onclick="edit()" value="修改" lay-submit lay-filter="login" style="width:100%;" type="submit">
    <hr class="hr15">
    <input id="back_edit" onclick="back()" value="取消" lay-submit lay-filter="login" style="width:100%;" type="submit">
    <hr class="hr15">
    <p id="idMessage" style="display: none;"></p>
</div>
<script src="/static/lib/layui/layui.js" charset="utf-8"></script>
<script src="/static/js/eleDel.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    function showADD() {
        layui.use('layer', function(){
            var layer = layui.layer;

            layer.open({
                type: 1,
                content: $('#showAddRFID')
            });
        });
    }
    function showEDIT(id) {
        var rfid_number_id = id.substring(4);
        $("#rfid_edit").val($("#"+rfid_number_id).text());
        $("#idMessage").text(id.substring(4));
        layui.use('layer', function(){
            var layer = layui.layer;

            layer.open({
                type: 1,
                content: $('#showEditRFID')
            });
        });
    }
    function back() {
        layui.use('layer', function(){
            var layer = layui.layer;

            layer.closeAll();
        });
    }
    function add() {
        var rfid = $("#rfid").val();
        if (rfid == null || rfid == "" || rfid == undefined){
            alert("卡号不能为空");
        } else {
            $.ajax({
                type : "POST",
                url : "/access/addRFID",
                data : {
                    "rfid" : rfid
                },
                async : false,
                cache : false,
                success : function(data) {
                    if (JSON.parse(data).msg == "success") {
                        alert("添加成功");
                        window.location.reload();
                        //返回
                        back();
                    }else {
                        alert("添加失败");
                    }
                },
                error : function() {
                    alert("系统错误");
                }
            });
        }
    }
    function edit() {
        var rfid = $("#rfid_edit").val();
        var id = $("#idMessage").text();
        console.log("rfid="+rfid+"/////"+"id="+id);
        $.ajax({
            type : "POST",
            url : "/access/editRFID",
            data : {
                "id" : id,
                "rfid" : rfid
            },
            async : false,
            cache : false,
            success : function(data) {
                if (JSON.parse(data).msg == "success") {
                    alert("修改成功");
                    window.location.reload();
                    //返回
                    back();
                }else {
                    alert("修改失败");
                }
            },
            error : function() {
                alert("系统错误");
            }
        });
    }
    function del(id) {
        var rfid_id = id.substring(3);
        var carNumber = $("#rfid_number"+id.substring(3)).text();
        var con = confirm('确认删除卡号 ' + carNumber + ' 吗?');
        if (con == true){
            $.ajax({
                type : "POST",
                url : "/access/delRFID",
                data : {
                    "id" : rfid_id
                },
                async : false,
                cache : false,
                success : function(data) {
                    if (JSON.parse(data).msg == "success") {
                        alert("删除成功");
                        window.location.reload();
                        //返回
                        back();
                    }else {
                        alert("删除失败");
                    }
                },
                error : function() {
                    alert("系统错误");
                }
            });
        } else {

        }

    }
</script>
</body>
</html>